package com.sk.skplanet.commute.actions;

import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import com.sk.skplanet.commute.vo.Data;

public class LoadingTask extends AsyncTask<Void, String, Void> {
	private ProgressDialog dialog;
	private String email;
	private List<Temp> list;
	private Context context;

	public LoadingTask(Context context, String email, List<Temp> list) {
		super();
		this.email = email;
		this.list = list;
		this.context = context;
	}

	@Override
	protected Void doInBackground(Void... unused) {
		try {
			Thread.sleep(1000);
			 HttpClient httpclient = new DefaultHttpClient();
			 // Vector<NameValuePair> nameValue = new Vector<NameValuePair>();
			 HttpGet httppost = new HttpGet(Data.URL);
			 HttpResponse responseGet = httpclient.execute(httppost);
			 HttpEntity resEntityGet = responseGet.getEntity();
			 Log.i("test123", EntityUtils.toString(resEntityGet));

			// HttpClient httpclient = new DefaultHttpClient();
			// Vector<NameValuePair> nameValue = new Vector<NameValuePair>();
			// // nameValue.add(new BasicNameValuePair("name", email));
			// HttpPost httppost = new HttpPost(Data.URL);
			// httppost.setEntity(new UrlEncodedFormEntity(nameValue,
			// HTTP.UTF_8));
			// InputStream is =
			// httpclient.execute(httppost).getEntity().getContent();
			// BufferedReader reader = new BufferedReader(new
			// InputStreamReader(is, "UTF-8"));
			// StringBuilder sb = new StringBuilder();
			// String line = null;
			// while ((line = reader.readLine()) != null)
			// sb.append(line + "\n");
			// is.close();
			// list.clear();
			// JSONArray jArray = new JSONArray(sb.toString());
			//
			// for (int i = 0; i < jArray.length(); i++) {
			// JSONObject json_data = jArray.getJSONObject(i);
			// Temp data = new Temp(json_data.getInt("id"),
			// json_data.getString("name"));
			// list.add(data);
			// }

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return (null);
	}

	@Override
	protected void onPreExecute() {
		dialog = ProgressDialog.show(context, "", "불러오는 중입니다.", true);
	}

	@Override
	protected void onProgressUpdate(String... item) {
	}

	@Override
	protected void onPostExecute(Void unused) {
		if (dialog != null) dialog.dismiss();

	}
}
